package com.lanou.projecta.topic;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.Volley;
import com.lanou.projecta.R;

import java.util.List;

/**
 * Created by dllo on 16/1/21.
 */
public class TopicFragmentBaseAdapter extends BaseAdapter{
    private List<BaseTopic.DataEntity.ExpertListEntity> base;
    private Context context;
    private RequestQueue queue;

    public TopicFragmentBaseAdapter(List<BaseTopic.DataEntity.ExpertListEntity> base, Context context) {
        queue = Volley.newRequestQueue(context);
        this.base = base;
        this.context = context;
    }
    public void getImage(NetworkImageView imageView, String url) {
        final ImageLoader imageLoader = new ImageLoader(queue, new ImageLoader.ImageCache() {
            @Override
            public Bitmap getBitmap(String url) {
                return null;
            }

            @Override
            public void putBitmap(String url, Bitmap bitmap) {
            }
        });
        imageView.setImageUrl(url, imageLoader);

    }

    @Override
    public int getCount() {
        if (base!=null){
        return base.size();}
        else {
            return 0;
        }
    }

    @Override
    public Object getItem(int i) {
        if (base!=null){
        return base.get(i);}
        else {
            return null;
        }
    }

    @Override
    public long getItemId(int i) {
        if (base!=null){
        return i;}
        else {
            return 0;
        }
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        String url = null;
        String url1 = null;
        if (base!=null){
            url = base.get(i).getPicurl();
            url1 = base.get(i).getHeadpicurl();
        }
        Handler1 handler1 = null;
        view = LayoutInflater.from(context).inflate(R.layout.topicitem,null);
        handler1 = new Handler1();
        handler1.title = (TextView) view.findViewById(R.id.topic_title);
        handler1.name = (TextView) view.findViewById(R.id.topic_tv_name);
        handler1.focus = (TextView) view.findViewById(R.id.topic_focus);
        handler1.type = (TextView) view.findViewById(R.id.topic_type);
        handler1.src = (ImageView) view.findViewById(R.id.topic_src);
        handler1.img = (NetworkImageView) view.findViewById(R.id.topic_iv_img);
        handler1.nameImg = (NetworkImageView) view.findViewById(R.id.topic_iv_name);
        view.setTag(handler1);
        if (base!=null){
            handler1.title.setText(base.get(i).getAlias());
            handler1.name.setText(base.get(i).getName());
            handler1.focus.setText(String.valueOf(base.get(i).getConcernCount()));
            handler1.type.setText(base.get(i).getClassification());
            getImage(handler1.img,url);
            getImage(handler1.nameImg,url1);


        }
//        String url = null;
//        if (base != null) {
//            url = base.get(i).getCover();
//        }
//        Handler1 handler = null;
//        view = LayoutInflater.from(context).inflate(R.layout.tv_item, null);
//        handler = new Handler1();
//        handler.title = (TextView) view.findViewById(R.id.tv_title);


        return view;
    }
    class Handler1{
        NetworkImageView img;
        NetworkImageView nameImg;
        ImageView src;
        TextView title;
        TextView focus;
        TextView type;
        TextView name;

    }
}
